package org.saxion.concurrency;
/**
 * 
 * @author Mathijs de Vries, Jeroen Katgert
 * 
 */
public class Buyer extends Person {

	private ShowRoom showRoom;
	private boolean isAlive = true;

	public Buyer(String name, ShowRoom showRoom) {
		super(name);
		this.showRoom = showRoom;
	}

	public void run() {
		while (isAlive) {
			try {
				showRoom.enterQueue();
				showRoom.waitOnBuyerInvite();
				showRoom.moveToShowRoom();
				walkAround();
				buyCar();
				showRoom.leaveShowRoom();
				isAlive = false;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

	private void buyCar() {
		System.out.println(getName() + " bought a car!");
	}

	private void walkAround() {
		justWait();
	}

	public String getCustomerName() {
		return getName();
	}

}
